<template>
    <a-modal :title="title" :width="width" :visible="visible" @cancel="handleCancel" cancelText="关闭">
        <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :md="6" :sm="8">
                        <a-form-item label="模型名称">
                            <a-input placeholder="请输入模型名称" v-model="queryParam.modelName"></a-input>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="8">
                        <a-form-item label="状态">
                            <j-dict-select-tag v-model="queryParam.status" placeholder="请选择状态"
                                dict-code="model_approve_status" />
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="8">
                        <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                            <a-button type="primary" @click="searchReset" icon="reload"
                                style="margin-left: 8px">清除条件</a-button>
                        </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :dataSource="dataSource"
            :pagination="ipagination" :loading="loading" @change="handleTableChange">
            <span slot="action" slot-scope="text, record">
                <a v-if="record.status == 0" @click="handleRemove(record)">删除</a>
                <a v-if="record.status == 1" @click="goBack(record)">撤回</a>
            </span>
        </a-table>
        <template slot="footer">
            <a-button @click="handleCancel">关闭</a-button>
        </template>
    </a-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, deleteAction } from '@/api/manage'
import columns from './indexColumns'
export default {
    name: 'BeefBooseRecordModal',
    mixins: [JeecgListMixin],
    data() {
        return {
            title: '',
            width: 1000,
            visible: false,
            columns: columns(this),
            url: {
                list: '/sjmx2/modelTemplateApprove/approveList',
                back: '/sjmx2/modelTemplateApprove/revoke',
                delete: '/sjmx2/modelTemplateApprove/delete'
            },
        }
    },
    methods: {
        show() {
            this.visible = true
            this.loadData(1)
        },
        close() {
            this.queryParam = {}
            this.visible = false
        },
        handleOk() {
            this.$emit('getdata', this.SelectData)
            this.visible = false
            this.queryParam = {}
        },
        handleCancel() {
            this.close()
        },
        handleRemove(data) {
            let that = this
            that.$confirm({
                title: '确认删除?',
                onOk() {
                    deleteAction(that.url.delete, { id: data.id }).then((res) => {
                        if (res.code == 200) {
                            that.$message.success('删除成功');
                            that.loadData()
                        }
                    })
                },
                onCancel() { },
            });
        },
        goBack(data) {
            let that = this
            that.$confirm({
                title: '确认撤回?',
                onOk() {
                    getAction(that.url.back, { id: data.id }).then((res) => {
                        if (res.code == 200) {
                            that.$message.success('撤回成功');
                            that.loadData()
                        }
                    })
                },
                onCancel() { },
            });
        },
    },
}
</script>